//
//  MainTabBar.swift
//  SinaWeiBo_18
//
//  Created by apple on 15/10/6.
//  Copyright © 2015年 apple. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {

    override func layoutSubviews() {
        
        super.layoutSubviews()

        var index : CGFloat = 0
        
        let width = UIScreen.mainScreen().bounds.width / 5
        let height = self.bounds.height
        
        let frame = CGRectMake(0, 0, width, height)
        
        for view in subviews{
        
            if view is UIControl && !(view is UIButton){
                
                view.frame = CGRectOffset(frame, index * width, 0)
                
                if index == 1 {
                
                    index++
                }
            
                index++
            }
        }
        composeButton.frame = CGRectOffset(frame, 2 * width, 0)
    }
    
    //懒加载得到按钮
    lazy var composeButton: UIButton = {
    
        let button = UIButton(type: UIButtonType.Custom)
        
//        button.backgroundColor = UIColor.orangeColor()
        
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState:UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        self.addSubview(button
        )
        
        return button
    }()

}
